/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.oracleandsxnd.erp.purchase.web;

import com.oracleandsxnd.erp.common.persistence.Page;
import com.oracleandsxnd.erp.common.persistence.TableSplitResult;
import com.oracleandsxnd.erp.common.utils.StringUtils;
import com.oracleandsxnd.erp.common.web.AjaxResult;
import com.oracleandsxnd.erp.common.web.BaseController;
import com.oracleandsxnd.erp.purchase.entity.PurchaseDetail;
import com.oracleandsxnd.erp.purchase.entity.PurchaseOrder;
import com.oracleandsxnd.erp.purchase.service.PurchaseOrderService;
import com.oracleandsxnd.erp.seting.entity.Company;
import com.oracleandsxnd.erp.seting.service.CompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 采购单Controller
 * @author 采购单
 * @version 2019-12-17
 */
@Controller
@RequestMapping(value = "purchase_purchaseOrder")
public class PurchaseOrderController extends BaseController {
	@Autowired
	private CompanyService companyService;
	@Autowired
	private PurchaseOrderService purchaseOrderService;
	@RequestMapping(value = {""})
	public String list(Model model) {

		return "erp/purchase/purchaseOrderList";
	}
	@RequestMapping(value = {"listData"})
	@ResponseBody
	public Object listData(PurchaseOrder purchaseOrder , HttpServletRequest request, HttpServletResponse response){
		Page<PurchaseOrder> page = purchaseOrderService.findPage(new Page<PurchaseOrder>(request, response), purchaseOrder);
		TableSplitResult<PurchaseOrder> result=new TableSplitResult<PurchaseOrder>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}


	@RequestMapping(value = "form")
	public String form(String id, Model model) {
		PurchaseOrder purchaseOrder=null;
		if (StringUtils.isNotBlank(id)){
			purchaseOrder = purchaseOrderService.get(id);
		}
		if (purchaseOrder == null){
			purchaseOrder = new PurchaseOrder();
		}
		model.addAttribute("purchaseOrder",purchaseOrder);
		Company c=new Company();
		c.setType("2");
		model.addAttribute("companys",companyService.findList(c));
		return "erp/purchase/purchaseOrderForm";
	}


	@RequestMapping(value = "save")
	public String save(PurchaseOrder purchaseOrder) {

		purchaseOrderService.save(purchaseOrder);
		return "redirect:/purchase_purchaseOrder/form";

	}

	@RequestMapping(value = "delete")
	@ResponseBody
	public AjaxResult  delete(PurchaseOrder purchaseOrder, RedirectAttributes redirectAttributes) {
		purchaseOrderService.delete(purchaseOrder);
		return success();
	}

	@RequestMapping(value = {"mx"})
	public String mx(Model model) {
		return "erp/purchase/purchaseOrdermxList";
	}
	@RequestMapping(value = {"mxlistData"})
	@ResponseBody
	public Object mxlistData(PurchaseDetail purchaseOrder , HttpServletRequest request, HttpServletResponse response){

		Page<PurchaseDetail> page = purchaseOrderService.findDPage(new Page<PurchaseDetail>(request, response), purchaseOrder);
		TableSplitResult<PurchaseDetail> result=new TableSplitResult<PurchaseDetail>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}
	@RequestMapping(value = {"jhmx"})
	public String xsmx(Model model) {
		return "erp/purchase/purchaseOrderjhmxList";
	}





	@RequestMapping(value = {"tj"})
	public String tj(Model model) {
		return "erp/purchase/purchaseOrdertjList";
	}
	@RequestMapping(value = {"tjlistData"})
	@ResponseBody
	public Object tjlistData(PurchaseDetail purchaseOrder , HttpServletRequest request, HttpServletResponse response){

		Page<PurchaseDetail> page = purchaseOrderService.findtjPage(new Page<PurchaseDetail>(request, response), purchaseOrder);
		TableSplitResult<PurchaseDetail> result=new TableSplitResult<PurchaseDetail>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}
	@RequestMapping(value = {"jhtj"})
	public String xstj(Model model) {
		return "erp/purchase/purchaseOrderjhtjList";
	}

	@RequestMapping(value = {"price"})
	public String price(Model model) {
		return "erp/purchase/purchaseOrderpriceList";
	}
	@RequestMapping(value = {"pricelistData"})
	@ResponseBody
	public Object pricelistData(PurchaseDetail purchaseOrder , HttpServletRequest request, HttpServletResponse response){

		Page<PurchaseDetail> page = purchaseOrderService.findpricePage(new Page<PurchaseDetail>(request, response), purchaseOrder);
		TableSplitResult<PurchaseDetail> result=new TableSplitResult<PurchaseDetail>(page.getPageNo(), page.getCount(), page.getList());
		return  result;
	}
 

}